<?php
/**
 * Created by PhpStorm.
 * User: qhzhyt
 * Date: 2018/10/4
 * Time: 17:30
 */

require_once '../conf/conf.php';

if (!isset($_POST['username']) || !isset($_POST['password'])) {
    echo(json_encode(['status' => 0, 'code' => 2]));
    exit(1);
}
$user = $db->get('user', '*', ['email' => $_POST['username']]);
if (!$user) {
    echo(json_encode(['status' => 0, 'code' => 5]));
    exit(1);
}
if (!pwCheck($_POST['password'], $user['password'])) {
    echo(json_encode(['status' => 0, 'code' => 4]));
    exit(1);
}
session_start();
$_SESSION['user'] = $user;
$user['password']=null;
printf(json_encode(['status' => 1, 'code' => 1, 'data' =>$user]));